home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
10,000 Great Games
/
10,000 Great Games.iso
/
Product
/
66
/
data1.cab
/
Source_Files
/
Src
/
MainFrm.cpp
< prev
next >
Wrap
C/C++ Source or Header
|
2000-01-16
|
9KB
|
404 lines
#include "stdafx.h"
#include "PlayerSelect.h"
#include "RandomProps.h"
#include "QuickStart.h"
#include "Gamma.h"
int generate_random = FALSE;
IMPLEMENT_DYNCREATE(CMainFrame, CFrameWnd)
BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)
//{{AFX_MSG_MAP(CMainFrame)
ON_WM_CREATE()
ON_COMMAND(ID_VIEW_GAMEAREA, OnViewGameArea)
ON_UPDATE_COMMAND_UI(ID_VIEW_GAMEAREA, OnUpdateViewGameArea)
ON_COMMAND(ID_SETTINGS_USEPARALLAXSCROLLING, OnSettingsDetaillevelUseParallaxScrolling)
ON_UPDATE_COMMAND_UI(ID_SETTINGS_USEPARALLAXSCROLLING, OnUpdateSettingsDetaillevelUseParallaxScrolling)
ON_COMMAND(ID_SETTINGS_USEVIDEOHARDWARE, OnSettingsDetaillevelUseVideoHardware)
ON_UPDATE_COMMAND_UI(ID_SETTINGS_USEVIDEOHARDWARE, OnUpdateSettingsDetaillevelUseVideoHardware)
ON_COMMAND(ID_SETTINGS_LOWDETALLEVEL, OnSettingsLowdetallevel)
ON_UPDATE_COMMAND_UI(ID_SETTINGS_LOWDETALLEVEL, OnUpdateSettingsLowdetallevel)
ON_COMMAND(ID_SETTINGS_SELECTPLAYERS, OnSettingsSelectplayers)
ON_COMMAND(ID_SETTINGS_ALWAYSSHOWPLAYERNAMES, OnSettingsAlwaysshowplayernames)
ON_UPDATE_COMMAND_UI(ID_SETTINGS_ALWAYSSHOWPLAYERNAMES, OnUpdateSettingsAlwaysshowplayernames)
ON_COMMAND(ID_VIEW_BACKGROUNDAREA, OnViewBackgroundarea)
ON_UPDATE_COMMAND_UI(ID_VIEW_BACKGROUNDAREA, OnUpdateViewBackgroundarea)
ON_COMMAND(ID_RUN_FROMHERE, OnRunFromHere)
ON_COMMAND(ID_RUN_LEVEL, OnRunLevel)
ON_UPDATE_COMMAND_UI(ID_VIEW_DEBUGINFO, OnUpdateViewDebuginfo)
ON_COMMAND(ID_VIEW_DEBUGINFO, OnViewDebuginfo)
ON_COMMAND(ID_SETTINGS_GAMEOPTIONS_NOARMOR, OnSettingsGameoptionsNoarmor)
ON_UPDATE_COMMAND_UI(ID_SETTINGS_GAMEOPTIONS_NOARMOR, OnUpdateSettingsGameoptionsNoarmor)
ON_COMMAND(ID_VIEW_GRID, OnViewGrid)
ON_UPDATE_COMMAND_UI(ID_VIEW_GRID, OnUpdateViewGrid)
ON_COMMAND(ID_FILE_NEW_RANDOM, OnFileNewRandom)
ON_COMMAND(ID_QUICKSTART, OnQuickstart)
ON_COMMAND(ID_SETTINGS_RANDOMLEVEL, OnSettingsRandomlevel)
ON_COMMAND(ID_SETTINGS_GAMEOPTIONS_GAMMACORRECTION, OnSettingsGammacorrection)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
static UINT indicators[] = {ID_SEPARATOR};
CMainFrame::CMainFrame()
{
}
CMainFrame::~CMainFrame()
{
}
int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
return -1;
if (!m_wndToolBar.Create(this) || !m_wndToolBar.LoadToolBar(IDR_MAINFRAME))
return -1;
if (!m_wndStatusBar.Create(this) || !m_wndStatusBar.SetIndicators(indicators, sizeof(indicators)/sizeof(UINT)))
return -1;
m_wndToolBar.SetBarStyle(m_wndToolBar.GetBarStyle() | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC);
m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);
EnableDocking(CBRS_ALIGN_ANY);
DockControlBar(&m_wndToolBar);
return 0;
}
BOOL CMainFrame::PreCreateWindow(CREATESTRUCT &cs)
{
return CFrameWnd::PreCreateWindow(cs);
}
#ifdef _DEBUG
void CMainFrame::AssertValid() const
{
CFrameWnd::AssertValid();
}
void CMainFrame::Dump(CDumpContext& dc) const
{
CFrameWnd::Dump(dc);
}
#endif
BOOL CMainFrame::Create(LPCTSTR lpszClassName, LPCTSTR lpszWindowName, DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID, CCreateContext* pContext)
{
return CWnd::Create(lpszClassName, lpszWindowName, dwStyle, rect, pParentWnd, nID, pContext);
}
void CMainFrame::OnViewBackgroundarea()
{
view_backgroundarea = !view_backgroundarea;
back_surface->all_dirty();
cEditable::editables_layer_change();
Invalidate();
}
void CMainFrame::OnUpdateViewBackgroundarea(CCmdUI* pCmdUI)
{
pCmdUI->SetCheck(view_backgroundarea || no_parallax);
pCmdUI->Enable(!no_parallax);
}
void CMainFrame::OnViewGameArea()
{
view_gamearea = !view_gamearea;
game_surface->all_dirty();
cEditable::editables_layer_change();
Invalidate();
}
void CMainFrame::OnUpdateViewGameArea(CCmdUI* pCmdUI)
{
pCmdUI->SetCheck(view_gamearea || no_parallax);
pCmdUI->Enable(!no_parallax);
}
void CMainFrame::OnSettingsDetaillevelUseParallaxScrolling()
{
CWaitCursor wait;
save_level(autosave_level);
deinit_game_loop();
deinit_game_data();
deinit_directdraw();
no_parallax = !no_parallax;
if (no_parallax)
warning("This mode is meant to speed up the game on slow computers.\n\n"
"THE LEVEL EDITOR WILL GIVE INPREDICTABLE RESULTS.\n\n"
"DO NOT EDIT IN THIS MODE!!");
init_directdraw_inawin();
init_game_data();
init_game_loop();
load_level(autosave_level);
Invalidate();
}
void CMainFrame::OnUpdateSettingsDetaillevelUseParallaxScrolling(CCmdUI* pCmdUI)
{
pCmdUI->SetCheck(!no_parallax);
}
void CMainFrame::OnSettingsDetaillevelUseVideoHardware()
{
CWaitCursor wait;
save_level(autosave_level);
deinit_game_loop();
deinit_game_data();
deinit_directdraw();
no_blit_hardware = !no_blit_hardware;
init_directdraw_inawin();
init_game_data();
init_game_loop();
load_level(autosave_level);
Invalidate();
}
void CMainFrame::OnUpdateSettingsDetaillevelUseVideoHardware(CCmdUI* pCmdUI)
{
pCmdUI->SetCheck(!no_blit_hardware && hardware_blit_caps);
pCmdUI->Enable(hardware_blit_caps);
}
void CMainFrame::OnSettingsLowdetallevel()
{
low_detail_level = !low_detail_level;
}
void CMainFrame::OnUpdateSettingsLowdetallevel(CCmdUI* pCmdUI)
{
pCmdUI->SetCheck(low_detail_level);
}
void CMainFrame::OnUpdateViewDebuginfo(CCmdUI* pCmdUI)
{
pCmdUI->SetCheck(debug);
}
void CMainFrame::OnViewDebuginfo()
{
debug = !debug;
Invalidate();
}
void CMainFrame::OnSettingsSelectplayers()
{
CPlayerSelect p;
p.DoModal();
}
void CMainFrame::OnSettingsAlwaysshowplayernames()
{
names_visible = !names_visible;
}
void CMainFrame::OnUpdateSettingsAlwaysshowplayernames(CCmdUI* pCmdUI)
{
pCmdUI->SetCheck(names_visible);
}
void CMainFrame::OnSettingsRandomlevel()
{
CRandomProps r;
r.DoModal();
}
void CMainFrame::OnQuickstart()
{
CQuickStart q;
q.DoModal();
}
void CMainFrame::OnRunFromHere()
{
int start;
// Save the level
SetCursor(LoadCursor(0, IDC_WAIT));
start = game_surface->start;
save_level(autosave_level);
// Do the game
SetCursor(0);
game_loop();
SetCursor(LoadCursor(0, IDC_WAIT));
// Restore previous state
deinit_game_loop();
init_game_loop();
load_level(autosave_level);
gamewindow->ScrollTo(0, start);
SetCursor(LoadCursor(0, IDC_ARROW));
// Redraw window
Invalidate();
}
void CMainFrame::OnRunLevel()
{
int start;
// Save current level
SetCursor(LoadCursor(0, IDC_WAIT));
start = game_surface->start;
save_level(autosave_level);
// Deinit game
deinit_game_loop();
deinit_game_data();
deinit_directdraw();
// Reinit game in full screen mode
inawin = FALSE;
init_directdraw_notinawin();
init_game_data();
// Load level
init_game_loop();
load_level(started_with_quickstart? construct("%s.bdl", quickstart_level) : autosave_level);
// Run level
SetCursor(0);
game_loop();
SetCursor(LoadCursor(0, IDC_WAIT));
// Deinit game
deinit_game_loop();
deinit_game_data();
deinit_directdraw();
// Reinit game in windowed mode
inawin = TRUE;
// Resize window
ResizeToFitGameArea();
// Reinit the game in a window
init_directdraw_inawin();
init_game_data();
init_game_loop();
// Reload the level
load_level(autosave_level);
gamewindow->ScrollTo(0, start);
SetCursor(LoadCursor(0, IDC_ARROW));
// Redraw window
Invalidate();
// Do Quickstart menu again?
if (started_with_quickstart)
{
PostMessage(WM_COMMAND, ID_QUICKSTART, 0);
started_with_quickstart = FALSE;
}
}
void CMainFrame::ResizeToFitGameArea()
{
// Resize so that game are will fit exactly in window
WINDOWPLACEMENT mw;
mainwindow->GetWindowPlacement(&mw);
WINDOWPLACEMENT gw;
gamewindow->GetWindowPlacement(&gw);
CRect gw_wanted(0, 0, SCREEN_X, SCREEN_Y);
gamewindow->CalcWindowRect(&gw_wanted, CWnd::adjustOutside);
int dx = (mw.rcNormalPosition.right - mw.rcNormalPosition.left) + (gw_wanted.right - gw_wanted.left) - (gw.rcNormalPosition.right - gw.rcNormalPosition.left) - 1;
int dy = (mw.rcNormalPosition.bottom - mw.rcNormalPosition.top) + (gw_wanted.bottom - gw_wanted.top) - (gw.rcNormalPosition.bottom - gw.rcNormalPosition.top) - 1;
mainwindow->MoveWindow(0, 0, dx, dy);
mainwindow->CenterWindow();
}
void CMainFrame::OnSettingsGameoptionsNoarmor()
{
no_armor = !no_armor;
}
void CMainFrame::OnUpdateSettingsGameoptionsNoarmor(CCmdUI* pCmdUI)
{
pCmdUI->SetCheck(no_armor);
}
void CMainFrame::OnViewGrid()
{
view_grid = !view_grid;
Invalidate();
}
void CMainFrame::OnUpdateViewGrid(CCmdUI* pCmdUI)
{
pCmdUI->SetCheck(view_grid);
}
void CMainFrame::OnFileNewRandom()
{
generate_random = TRUE;
PostMessage(WM_COMMAND, ID_FILE_NEW, 0);
}
void CMainFrame::OnSettingsGammacorrection()
{
CGamma g;
g.DoModal();
}